package com.start.workflow.core.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.start.common.api.Result;
import com.start.common.dataRule.DataQueryConstructor;
import com.start.workflow.act.StartActMyHandlerAuthTask;
import com.start.workflow.act.StartActWaitAuthTask;
import com.start.workflow.core.manage.StartActInstManage;
import com.start.workflow.core.manage.StartActUserTaskManage;
import com.start.workflow.core.service.StartActBusinessService;
import com.start.workflow.vo.StartSubmitActTask;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Tag(name = "start流程API")
@RestController
@RequestMapping("/startMyActTaskApi")
public class StartActTaskApi {


    @Autowired
    private StartActUserTaskManage startActUserTaskManage;
    @Autowired
    private StartActBusinessService startActBusinessService;
    @Autowired
    private StartActInstManage actInstManage;


    @Operation(summary = "分页查询参与的申请")
    @GetMapping("/pageMyDoneTask")
    public Result<?> pageMyDoneTask(Page<StartActMyHandlerAuthTask> page) {
        QueryWrapper<StartActMyHandlerAuthTask> queryWrapper = DataQueryConstructor.createEntity(StartActMyHandlerAuthTask.class);
        return Result.ok(startActUserTaskManage.pageMyDoneTask(page, queryWrapper));
    }

    @Operation(summary = "分页查询我的待办流程")
    @GetMapping("/pageMyWaitAuthTask")
    public Result<?> pageMyWaitAuthTask(Page<StartActWaitAuthTask> page) {
        QueryWrapper<StartActWaitAuthTask> queryWrapper = DataQueryConstructor.createEntity(StartActWaitAuthTask.class);
        return Result.ok(startActUserTaskManage.pageMyWaitAuthTask(page, queryWrapper));
    }

    @Operation(summary = "根据流程业务id获取流程详情")
    @GetMapping("/getWaitAuthTaskDetail/{taskId}")
    public Result<?> getWaitAuthTaskDetail(@PathVariable("taskId") String taskId,
                                           @RequestParam(required = false) boolean loadFormOption) {
        return Result.ok(actInstManage.getWaitAuthTaskDetail(taskId, loadFormOption));
    }

    /**
     * 处理申请
     *
     * @return
     */
    @Operation(summary = "用户处理节点")
    @PostMapping("/handlerNodeApply/{taskId}")
    public Result<?> handlerNodeApply(@PathVariable("taskId") String taskId, @RequestBody StartSubmitActTask actApply) {
        startActUserTaskManage.handlerNodeApply(taskId, actApply);
        return Result.ok();
    }


}
